<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title am-cf">模板列表</div>
                </div>
                <div class="widget-body am-fr">
                    <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                        <div class="am-form-group">
                            <div class="am-btn-toolbar">
                                <div class="am-btn-group am-btn-group-sm">
                                    <a href="javascript:void(0);" class="hema-add am-btn am-btn-primary am-radius">
                                        <span class="am-icon-plus"></span> 添加
                                    </a>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="am-u-sm-12">
                        <table width="100%" class="am-table am-table-hover tpl-table-black">
                            <thead>
                            <tr>
                                <th>编号ID</th>
                                <th>模板名称</th>
								<th>识别编号</th>
                                <th>代理价</th>
                                <th>显示排序</th>
                                <th>模板状态</th>
                                <th>添加时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {if sizeof($list) > 0}
                                {foreach $list as $item}
                                <tr>
                                    <td class="am-text-middle">{$item['template_id']}</td>
                                    <td class="am-text-middle">{$item['name']}</td>
									<td class="am-text-middle">{$item['app_type']}</td>
                                    <td class="am-text-middle">
                                        <p>单门店：{$item['single_price']}</p>
                                        <p>多门店：{$item['many_price']}</p>
                                    </td>
                                    <td class="am-text-middle">{$item['sort']}</td>
                                    <td class="am-text-middle">
										<span class="j-status am-badge x-cur-p {$item['status']['value'] == 10 ? ' am-badge-success' : ' am-badge-warning'}" 
											 data-id="{$item['template_id']}"
											 data-status="{$item['status']['value']}">
										      {$item['status']['text']}
										</span>
                                    </td>
                                    <td class="am-text-middle">{$item['create_time']}</td>
                                    <td class="am-text-middle">
                                        <div class="tpl-table-black-operation">
                                            <a href="javascript:;" class="hema-edit" data-id="{$item['template_id']}">
                                                <i class="am-icon-pencil"></i> 编辑
                                            </a>
                                            <a href="javascript:;" class="hema-del tpl-table-black-operation-del"
                                               data-id="{$item['template_id']}">
                                                <i class="am-icon-trash"></i> 删除
                                            </a>
                                        </div>
                                    </td>
                                </tr>
                                {/foreach}
                            {else /}
                                <tr>
                                    <td colspan="8" class="am-text-center">暂无记录</td>
                                </tr>
                            {/if}
                            </tbody>
                        </table>
                    </div>
                    <div class="am-u-lg-12 am-cf">
                        <div class="am-fr">{:$list->render()} </div>
                        <div class="am-fr pagination-total am-margin-right">
                            <div class="am-vertical-align-middle">总记录：{:$list->total()}</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="applet/template/add" /}
{include file="applet/template/edit" /}
<script>
    $(function () {
         //添加
        $('.hema-add').on('click', function () {
            $.get("{:url('applet.template/add')}", function (result) {
				if(result.code == 0){
				    $.show_error(result.msg);
				    return false;
				}
                $.showAction({
                    title: '添加', 
                    area: '750px', 
                    content: template('tpl-add', {category:result.data.category}), 
                    uCheck: true, 
                    success: function ($content) {
                        var $many = $('.many'), $single = $('.single');
                        $many.hide();
                        $single.hide();
                        // 切换
                        $('#app-type').change(function (e) {
                            var index = e.target.options.selectedIndex;
                            $many.hide();
                            $single.hide();
                            if(index > 0){
                                if(result.data.category[index-1].is_many == 1){
                                    $many.show();
                                }else{
                                    $single.show();
                                }
                            }
                        });
                        $('#my-form').formPost({
                            url: "{:url('applet.template/add')}"
                        });
                    }, 
                    btn2: function ($content) {
                        return true;
                    }
                });
            });
        });
        //编辑
        $('.hema-edit').on('click', function () {
            var data = $(this).data();
            $.get("{:url('applet.template/edit')}?id=" + data.id, function (result) {
				if(result.code == 0){
				    $.show_error(result.msg);
				    return false;
				}
				$.showAction({
                    title: '编辑', 
                    area: '750px', 
                    content: template('tpl-edit', {model:result.data.model}), 
                    uCheck: true, 
                    success: function ($content) {
                        var $many = $('.many'), $single = $('.single');
                        $many.hide();
                        $single.hide();
                        if(result.data.model.is_many == 1){
                            $many.show();
                        }else{
                            $single.show();
                        }
                        $('#my-form').formPost({
                            url: "{:url('applet.template/edit')}?id=" + data.id
                        });
                    }, 
                    btn2: function ($content) {
                        return true;
                    }
                });
            });
        });
        // 切换上架状态
        $('.j-status').click(function () {
            var data = $(this).data();
			var msg = '确定要'+(parseInt(data.status) === 10 ? '下架' : '上架')+'该模板？';
            var url = "{:url('applet.template/status')}";
			$('.j-status').del('id', url,msg);
        });
        // 删除元素
        var url = "{:url('applet.template/delete')}";
        $('.hema-del').del('id', url);

    });
</script>

